<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增仪器设备')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-list-add">
        <h4 class="form-header h4">仪器设备信息</h4>
        <div class="form-group">
            <label class="col-sm-3 control-label">仪器名称：</label>
            <div class="col-sm-8">
                <input name="name" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">型号规格：</label>
            <div class="col-sm-8">
                <input name="specification" class="form-control" type="text">
            </div>
        </div>
        <input name="department" type="hidden" id="treeId"/>
        <div class="form-group">
            <label class="col-sm-3 control-label">所属部门：</label>
            <div class="col-sm-8">
                <input name="deptName" onclick="selectDeptTree()" id="treeName" type="text" placeholder="请选择归属部门" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">主要技术指标：</label>
            <div class="col-sm-8">
                <input name="indicator" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">检定有效期(单位：天)：</label>
            <div class="col-sm-8">
                <input name="validTime" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">设备状态：</label>
            <div class="col-sm-8">
<!--                <input name="instrumentStatus" class="form-control" type="text">-->
                <select name="instrumentStatus" class="form-control">
                    <option value="正常">正常</option>
                    <option value="报废">报废</option>
                    <option value="维修">维修</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">存放位置：</label>
            <div class="col-sm-8">
                <!--                    <input name="saveLocation" class="form-control" type="text">-->
                <select name="saveLocation" class="form-control" >
                    <option th:each="item,info:${wareHouse}"th:object="${item}" th:value="*{id}"><span th:text="*{name}"></span></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">创建人：</label>
            <div class="col-sm-8">
                <input name="creater" class="form-control" th:value="${user.userId}"  type="hidden">
                <span th:text="${user.userName}"></span>
                <!--                    <input name="creater" class="form-control" disabled type="text">-->
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">创建时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="createdTime" class="form-control createTime" disabled placeholder="自动获取当前时间" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea name="remark" class="form-control"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否出库：</label>
            <div class="col-sm-8">
                <!--                    <input name="instrumentOut" class="form-control" type="text">-->
                <select name="instrumentOut" class="form-control" type="text">
                    <option value="已出库">已出库</option>
                    <option value="未出库">未出库</option>
                </select>
            </div>
        </div>
        <!--  <h4 class="form-header h4">sys_warehouse信息</h4>
          <div class="row">
              <div class="col-sm-12">
                  <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
                  <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
                  <div class="col-sm-12 select-table table-striped">
                      <table id="bootstrap-table"></table>
                  </div>
              </div>
          </div>-->
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "system/list"
    $("#form-list-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        $('.createTime').val(getNowTime())
        console.log($('.createTime').val())
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-list-add').serialize());
        }
    }

    $("input[name='createdTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
    /* 用户管理-新增-选择部门树 */
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/user/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        console.log(deptId)
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    //获取当前时间
    function getNowTime() {
        var date = new Date();
        //年 getFullYear()：四位数字返回年份
        var year = date.getFullYear();  //getFullYear()代替getYear()
        //月 getMonth()：0 ~ 11
        var month = date.getMonth() + 1;
        //日 getDate()：(1 ~ 31)
        var day = date.getDate();
        //时 getHours()：(0 ~ 23)
        var hour = date.getHours();
        //分 getMinutes()： (0 ~ 59)
        var minute = date.getMinutes();
        //秒 getSeconds()：(0 ~ 59)
        var second = date.getSeconds();

        var time = year + '-' + addZero(month) + '-' + addZero(day) + ' ' + addZero(hour) + ':' + addZero(minute) + ':' + addZero(second);
        return time;
    }


    //小于10的拼接上0字符串
    function addZero(s) {
        return s < 10 ? ('0' + s) : s;
    }

    $(function() {
        var options = {
            pagination: false,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            sidePagination: "client",
            columns: [{
                checkbox: true
            },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                        var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                        return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'name',
                    align: 'center',
                    title: '库房名称',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysWarehouseList[%s].name' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'line',
                    align: 'center',
                    title: '规格',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysWarehouseList[%s].line' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'type',
                    align: 'center',
                    title: '类型',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysWarehouseList[%s].type' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'createName',
                    align: 'center',
                    title: '创建人',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysWarehouseList[%s].createName' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'createTime',
                    align: 'center',
                    title: '创建时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysWarehouseList[%s].createTime' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'userState',
                    align: 'center',
                    title: '使用状态',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysWarehouseList[%s].userState' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'state',
                    align: 'center',
                    title: '状态',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysWarehouseList[%s].state' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
        };
        $.table.init(options);
    });

    function addRow() {
        var count = $("#" + table.options.id).bootstrapTable('getData').length;
        var row = {
            index: $.table.serialNumber(count),
            name: "",
            line: "",
            type: "",
            createName: "",
            createTime: "",
            userState: "",
            state: "",
        }
        sub.addRow(row);
    }
</script>
</body>
</html>